export default class UglyTreeNode {
    constructor(val) {

        let self = this

        this.value = val ? val : null
        this.valueListener = null

        this.childArray = []

        this.setValueListener = function (listener) {
            if(listener === null || listener instanceof Function) {
                self.valueListener = listener
            }
            return true
        }

        this.setValue = function (value) {
            self.value = value
            if (self.valueListener) {
                self.valueListener(value)
            }
        }

        this.getValue = function () {
            return self.value
        }

        this.addChild = function (child) {
            if (child instanceof TreeNode) {
                self.childArray.push(child)
                return true
            }
            return false
        }

        this.removeChild = function (child) {
            if (child instanceof TreeNode) {
                self.childArray.splice(self.childArray.indexOf(child), 1)
                return true
            }
            return false
        }

        this.children = function () {
            return self.childArray
        }

    }
}
